// app.js
const clearApi = require("./utils/clearStorage")
App({
  // 加载的时候向用户访问授权
  onLaunch() {

  },
  globalData: {
    userInfo: null
  },
  onShow() {
    // 初始化时获取手机可用区域页面宽高
    wx.getSystemInfo({
      success(res) {
        wx.setStorageSync('windowHeight', res.windowHeight)
        wx.setStorageSync('windowWidth', res.windowWidth)
      }
    })
    // 获取右上角胶囊坐标，为计算高度值为搜索框动态固定位置
    var menuResponse = wx.getMenuButtonBoundingClientRect()
    let capsuleHeight = menuResponse.height
    let capsuleTop = menuResponse.top
    //计算出的搜索框上边距
    let searchTop = capsuleTop - (34 / 2 - capsuleHeight / 2)
    //计算出整体布局上边框与胶囊底部平行的预期上边距高度
    let orderTopHeight = capsuleHeight + capsuleTop
    wx.setStorageSync('searchTop', searchTop)
    wx.setStorageSync('orderTopHeight', orderTopHeight)
  },
  onHide() {
    // 小程序切入后台或者退出时清除缓存
    clearApi.ClearHeightAndWidth()
    clearApi.ClearOrderTopHeight()
    clearApi.ClearSearchTop()
    // clearApi.ClearUserToken()
  }
})